package cn.zqy.demo3.day02.DataSource;

import cn.zqy.demo3.day02.Utils.JDBCUtils;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.sql.Statement;
/**
 * 使用新的工具类
 */
public class Demo04DruidUseUtils {
    /*
     * 完成添加操作：给a表添加一条记录
     */
    public static void main(String[] args) {
        Connection con = null;
        PreparedStatement sta = null;
        try {
            //1.获取连接
            con = JDBCUtils.getConnection();
            //2.定义sql
            String sql = "insert  into a values (89, ?, ?)";
            //3.获取prepareStatement对象
            sta = con.prepareStatement(sql);
            //4.给？赋值
            sta.setInt(2, 999);
            sta.setString(1, "周华健");
            //5.执行sql
            sta.executeUpdate();
        } catch (SQLException e) {
            e.printStackTrace();
        } finally {
            JDBCUtils.close(sta, con);
        }

    }
}
